package cgd;

import cdp.Compra;
import java.util.Date;
import java.util.List;
import javax.persistence.Query;
import javax.persistence.TemporalType;

public class CompraDao extends DaoJpa<Compra> {

    private static CompraDao instance = null;

    public static CompraDao getInstance() {
        if (instance == null) {
            instance = new CompraDao();
        }
        return instance;
    }

    public List<Compra> consultarPeriodo(Date date) throws Exception {
        try {
            Query q = em.createQuery("SELECT t FROM Compra t WHERE t.dataCompra BETWEEN ?1  AND CURRENT_DATE ");
            q.setParameter(1, date, TemporalType.DATE);
            return q.getResultList();
        } catch (Exception ex) {
            throw ex;
        }
    }

    public List<Compra> obterTodos() throws Exception {
        return buscar(new Compra());
    }
}
